package es.cazadoresmadridejos.model;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.springframework.web.multipart.commons.CommonsMultipartFile;

@Entity(name="Advertisement")
@Table(name="articulo")
public class Advertisement extends BaseEntity{

	/**
	 * 
	 */
	private static final long serialVersionUID = 573477274394828590L;
	
	public enum AdvertisementType {
		RIFLE,ESCOPETA,OTRAS_ARMAS,VEHICULO, VISOR,OPTICA,PERRO
	}
	
	public enum OfferType{
		COMPRAR,VENDER,REGALAR,CAMBIAR,ALQUILAR
	}
	
	private Partner partner;
	private Date date;
	private String image;
	private AdvertisementType advertisementType;
	private OfferType offerType;
	private Integer active;
	private BigDecimal amount;
	private String description;
	//transient
	private CommonsMultipartFile  file;	
	

	@ManyToOne(optional=false)
	@JoinColumn(name="usuario")	
	public Partner getPartner() {
		return partner;
	}
	public void setPartner(Partner partner) {
		this.partner = partner;
	}
	@Column(name="fecha")
	public Date getDate() {
		return date;
	}
	public void setDate(Date date) {
		this.date = date;
	}
	@Column(name="imagen")
	public String getImage() {
		return image;
	}
	public void setImage(String image) {
		this.image = image;
	}
	
	@Column(name="tipo_articulo")
	@Enumerated(EnumType.STRING)
	public AdvertisementType getAdvertisementType() {
		return advertisementType;
	}
	public void setAdvertisementType(AdvertisementType advertisementType) {
		this.advertisementType = advertisementType;
	}
	@Column(name="tipo_oferta")
	@Enumerated(EnumType.STRING)
	public OfferType getOfferType() {
		return offerType;
	}
	public void setOfferType(OfferType offerType) {
		this.offerType = offerType;
	}
	@Column(name="precio")
	public BigDecimal getAmount() {
		return amount;
	}
	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}
	@Column(name="texto")
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	@Column(name="activo",nullable=false)
	public Integer getActive() {
		return active;
	}
	public void setActive(Integer active) {
		this.active = active;
	}
	@Transient
	public CommonsMultipartFile getFile() {
		return file;
	}
	public void setFile(CommonsMultipartFile file) {
		this.file = file;
		this.image = file.getOriginalFilename();
	}
	
}
